<template>
  <back-dialog-base
    :title="title"
    :visible="visibleDialog"
    :hasFooter="false"
    width="21rem"
  >
    <template #content>
      <div class="content-warp">
        <div class="left-box">
          <div class="pic-box">
            <div class="pic"></div>
          </div>
          <div class="info-box">
            <p>发布屏编号: {{ pubNum }}</p>
            <p>位置信息: {{ location }}</p>
          </div>
        </div>
        <div class="right-box">
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            height="100%"
          >
            <el-table-column label="序号" type="index" width="50" />
            <el-table-column prop="fileName" label="任务名称" width="120">
            </el-table-column>
            <el-table-column prop="contentType" label="内容类型">
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="120">
              <template #default="{ row }">
                <div class="action-row">
                  <span class="action-btn" @click="handleReview(row)"
                    >预览</span
                  >
                  <div class="has-more"></div>
                  <span class="action-btn" @click="handlePublish(row)"
                    >下发</span
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
          <div class="review-box" v-show="review">
            <div class="img-box">
              <span class="close-btn" @click="() => (review = false)">×</span>
              <img class="img" :src="imgUrl" alt="" />
              <div class="title">{{ picData.fileName }}</div>
            </div>
          </div>
        </div>
      </div>
    </template>
  </back-dialog-base>
</template>

<script setup>
import { defineProps, ref, watch, defineEmits } from 'vue'
import BackDialogBase from '@/components/BackDialogBase'
import { imgList } from '@/api/back'
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  visibleDialog: {
    type: Boolean,
    default: false
  },
  datas: {
    type: Array,
    default: () => []
  }
})
const emits = defineEmits(['handlePub'])
const pubNum = ref('')
const location = ref('')
const tableData = ref([])
const loading = ref(false)
const getListData = async () => {
  loading.value = true
  const res = await imgList()
  loading.value = false
  tableData.value = res
}
getListData()
const review = ref(false)

const picData = ref({})
const imgUrl = ref('')
const handleReview = (row) => {
  review.value = true
  picData.value = row
}

const handlePublish = (row) => {
  emits('handlePub', row.fileName, row.contentType, props.datas)
}

watch(
  () => picData.value,
  () => {
    imgUrl.value = require('@@/images/back/' + picData.value.fileName)
  }
)
watch(
  () => props.datas,
  () => {
    const len = props.datas.length
    if (len === 1) {
      pubNum.value = props.datas[0].screenCode
      location.value = props.datas[0].locationInfo
    }
    if (len > 1) {
      pubNum.value =
        props.datas[0].screenCode + '~' + props.datas[len - 1].screenCode
      location.value = props.datas[0].locationInfo
    }
  }
)
</script>

<style lang="scss" scoped>
.content-warp {
  width: 100%;
  height: 100%;
  display: flex;
  .left-box {
    display: flex;
    flex-direction: column;
    margin-right: 50px;
    margin-left: 20px;
    background: v-bind(color);
    .pic-box {
      width: 134px;
      height: 304px;
      padding: 10px 27px 8px 37px;
      background: rgba(255, 255, 255, 0.39);
      box-shadow: 0px 0px 10px rgba(153, 153, 153, 0.2);
      opacity: 1;
      border-radius: 5px;
      .pic {
        width: 100%;
        height: 100%;
        background: url(~@@/images/back/light.png) no-repeat;
        background-size: contain;
      }
    }
    .info-box {
      width: 165px;
      margin-top: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      line-height: 19px;
      color: #5d6c8e;
      > p {
        width: 162px;
        margin-bottom: 10px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }
  }
  .right-box {
    height: 340px;
    flex: 1;
    margin-right: 10px;
    border: 1px solid #d4dae5;
    border-bottom: 0px;
    position: relative;
    .action-row {
      display: flex;
      .action-btn {
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        line-height: 19px;
        color: #ff9502;
        cursor: pointer;
      }
      .has-more {
        width: 2px;
        height: 10px;
        background: #ff9e02;
        margin-right: 10px;
        margin-left: 10px;
        margin-top: 5px;
      }
    }
    .review-box {
      position: absolute;
      top: 0;
      left: 0;
      .img-box {
        width: 193px;
        height: 340px;
        background: rgba(255, 255, 255, 0.39);
        box-shadow: 0px 0px 10px rgba(153, 153, 153, 0.2);
        border-radius: 5px;
        position: relative;
        .close-btn {
          width: 20px;
          height: 20px;
          color: #ff9502;
          font-size: 18px;
          border-radius: 50%;
          background: #fff;
          position: absolute;
          // border: 1px solid #ff9502;
          text-align: center;
          line-height: 20px;
          font-weight: bold;
          top: 6px;
          right: 6px;
          cursor: pointer;
        }
        .img {
          width: 193px;
          height: 304px;
        }
        .title {
          width: 100%;
          height: 36px;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          line-height: 36px;
          text-align: center;
          color: #5d6c8e;
        }
      }
    }
  }
}
</style>
